package com.yf.zzmusic.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yf.zzmusic.common.Constants;
import com.yf.zzmusic.common.PageInfo;
import com.yf.zzmusic.common.Result;
import com.yf.zzmusic.pojo.dto.favoriteCount.FavoriteDeleteDTO;
import com.yf.zzmusic.pojo.dto.favoriteCount.FavoritePageDTO;
import com.yf.zzmusic.pojo.vo.favoriteCount.FavoriteCountOfAlbumVO;
import com.yf.zzmusic.pojo.vo.favoriteCount.FavoriteCountOfMusicCollectVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

import com.yf.zzmusic.service.IFavoriteCountService;
import com.yf.zzmusic.pojo.entity.FavoriteCount;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 收藏数表。用于存储音乐、歌单和专辑的收藏数 前端控制器
 * </p>
 *
 * @author
 * @since 2024-03-19
 */
@RestController
@RequestMapping("/favoritecount")
public class FavoriteCountController {
    @Resource
    private IFavoriteCountService favoriteCountService;

    @PostMapping("/insert")
    public Result save(@Validated @RequestBody FavoriteCount favoriteCount) {
        boolean result=favoriteCountService.save(favoriteCount);
        if (result) {
            return Result.success("新增成功", null);
        } else {
            return Result.error("新增失败");
        }
    }

    @DeleteMapping("/delete")
    public Result delete(@Validated FavoriteDeleteDTO favoriteDeleteDTO) {
        boolean result = favoriteCountService.deleteFavoriteByQuery(favoriteDeleteDTO);
        if (result) {
            return Result.success("删除成功", null);
        } else {
            return Result.error("删除失败");
        }
    }

    @GetMapping("/page/musiccollect")
    public Result findPageOfMusicCollect(@Validated FavoritePageDTO favoritePageDTO) {
        PageInfo<FavoriteCountOfMusicCollectVO> pageInfo=favoriteCountService.getFavoriteOfMusicCollect(favoritePageDTO);
        if (pageInfo.getData().size()>0){
            return Result.success("查询成功",pageInfo);
        }else{
            return Result.error(Constants.NO_CONTENT,"列表为空");
        }
    }

    @GetMapping("/page/album")
    public Result findPageOfAlbum(@Validated FavoritePageDTO favoritePageDTO) {
        PageInfo<FavoriteCountOfAlbumVO> pageInfo=favoriteCountService.getFavoriteOfAlbum(favoritePageDTO);
        if (pageInfo.getData().size()>0){
            return Result.success("查询成功",pageInfo);
        }else{
            return Result.error(Constants.NO_CONTENT,"列表为空");
        }
    }
}

